home *** CD-ROM | disk | FTP | other *** search
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.Point;
- import java.awt.Polygon;
- import java.awt.Rectangle;
- import java.awt.Toolkit;
-
- class CComboBox {
- static final int BUTTON_WIDTH = 15;
- static final Point TEXT_SPACING = new Point(5, 4);
- private int m_nFlags;
- private int m_nButtonState;
- private CRect m_rcDraw;
- private CRect m_rcText;
- private CRect m_rcButton;
- private CRect m_rcListBox;
- private Font m_Font;
- private Color m_rgbFg;
- private Color m_rgbBg;
- private String m_strSelection;
- private boolean m_bHasFocus;
- private boolean m_bListVisible;
- private CListBox m_ListBox;
-
- public boolean ProcessMouseMove(Point var1) {
- if (this.m_rcListBox.inside(var1.x, var1.y)) {
- this.m_ListBox.ProcessMouseMove(var1);
- } else if (this.m_rcButton.inside(var1.x, var1.y) && Utils.StateTest(this.m_nButtonState, 8) && Utils.StateTest(this.m_nButtonState, 4)) {
- this.m_nButtonState = Utils.StateClear(this.m_nButtonState, 4);
- this.DrawButton(Globals.thePresView.GetDC());
- } else if (!this.m_rcButton.inside(var1.x, var1.y) && Utils.StateTest(this.m_nButtonState, 8) && !Utils.StateTest(this.m_nButtonState, 4)) {
- this.m_nButtonState = Utils.StateSet(this.m_nButtonState, 4);
- this.DrawButton(Globals.thePresView.GetDC());
- }
-
- return false;
- }
-
- public void SetRect(CRect var1) {
- int var2 = this.m_rcListBox.height;
- this.m_rcDraw.reshape(var1);
- this.SetRegions();
- this.m_rcListBox.height = var2;
- }
-
- public void HideList() {
- this.m_bListVisible = false;
- }
-
- public void DrawControl() {
- this.DrawControl(Globals.thePresView.GetDC(), this.m_rcDraw);
- }
-
- public void DrawControl(Graphics var1, CRect var2) {
- if (var1 == null) {
- var1 = Globals.thePresView.GetDC();
- }
-
- if (var2 == null) {
- var2 = this.m_rcDraw;
- }
-
- if (var1 != null && var2 != null) {
- Graphics var3 = var1.create();
- var3.clipRect(var2.x, var2.y, var2.width, var2.height);
- var3.setFont(this.m_Font);
- int var4 = var3.getFontMetrics().getAscent();
- var3.setColor(this.m_rgbBg);
- var3.fillRect(this.m_rcText.x, this.m_rcText.y, this.m_rcText.width, this.m_rcText.height);
- var3.setColor(Color.black);
- var3.drawRect(this.m_rcText.x, this.m_rcText.y, this.m_rcDraw.width - 1, this.m_rcText.height - 1);
- if (this.m_strSelection.length() > 0) {
- var3.setColor(this.m_rgbFg);
- var3.drawString(this.m_strSelection, this.m_rcText.x + TEXT_SPACING.x, this.m_rcText.y + var4 + TEXT_SPACING.y);
- }
-
- this.DrawButton(var3);
- if (this.m_bListVisible) {
- this.m_ListBox.DrawControl(var3, this.m_rcListBox);
- }
- }
-
- }
-
- public boolean ProcessMouseUp(Point var1) {
- this.m_nButtonState = 0;
- if (this.m_bListVisible) {
- if (this.m_rcListBox.inside(var1.x, var1.y)) {
- this.m_ListBox.ProcessMouseUp(var1);
- this.m_strSelection = this.m_ListBox.GetSel();
- this.m_bListVisible = false;
- Globals.thePresView.Render(this.m_rcDraw);
- Globals.thePresView.Draw((Graphics)null, this.m_rcDraw);
- } else if (this.m_rcButton.inside(var1.x, var1.y)) {
- this.DrawButton(Globals.thePresView.GetDC());
- }
- }
-
- this.m_bHasFocus = false;
- return false;
- }
-
- public boolean HasFocus() {
- return this.m_bHasFocus;
- }
-
- CComboBox(int var1, CRect var2) {
- this.m_nFlags = var1;
- this.m_rcDraw = var2;
- this.m_rcText = new CRect();
- this.m_rcButton = new CRect();
- this.m_rcListBox = new CRect();
- this.m_Font = new Font("Helvetica", 0, 20);
- this.m_rgbFg = new Color(0, 0, 0);
- this.m_rgbBg = new Color(255, 255, 255);
- this.m_strSelection = "";
- this.m_bHasFocus = false;
- this.m_bListVisible = false;
- int var3 = 17;
- if ((var1 & 4) != 0) {
- var3 |= 4;
- }
-
- this.m_ListBox = new CListBox(var3, this.m_rcListBox);
- this.m_ListBox.SetFont(this.m_Font);
- this.SetRegions();
- }
-
- public void SetBgColour(Color var1) {
- this.m_rgbBg = var1;
- this.m_ListBox.SetBgColour(var1);
- }
-
- public void SetFgColour(Color var1) {
- this.m_rgbFg = var1;
- this.m_ListBox.SetFgColour(var1);
- }
-
- public void SetRegions() {
- int var1 = Toolkit.getDefaultToolkit().getFontMetrics(this.m_Font).getHeight();
- this.m_rcText.reshape(this.m_rcDraw.x, this.m_rcDraw.y, this.m_rcDraw.width - 15, var1 + 2 * TEXT_SPACING.y);
- this.m_rcButton.reshape(this.m_rcDraw.x + (this.m_rcDraw.width - 15), this.m_rcDraw.y, 15, this.m_rcText.height);
- this.m_rcListBox.reshape(this.m_rcDraw.x, this.m_rcDraw.y + this.m_rcText.height + 1, this.m_rcDraw.width, 0);
- this.m_rcDraw.height = this.m_rcText.height + this.m_rcListBox.height + 1;
- }
-
- private void DrawButton(Graphics var1) {
- Color var2 = Color.white;
- Color var3 = Color.darkGray;
- byte var4 = 0;
- var1.setColor(Color.black);
- var1.drawRoundRect(this.m_rcButton.x, this.m_rcButton.y, this.m_rcButton.width - 1, this.m_rcButton.height - 1, 2, 2);
- var1.setColor(Color.lightGray);
- var1.fillRect(this.m_rcButton.x + 2, this.m_rcButton.y + 2, this.m_rcButton.width - 4, this.m_rcButton.height - 4);
- if (Utils.StateTest(this.m_nButtonState, 8) && !Utils.StateTest(this.m_nButtonState, 4)) {
- var2 = Color.darkGray;
- var3 = Color.white;
- var4 = 1;
- }
-
- var1.setColor(var2);
- var1.drawLine(this.m_rcButton.x + 1, this.m_rcButton.y + 1, this.m_rcButton.x + this.m_rcButton.width - 2, this.m_rcButton.y + 1);
- var1.drawLine(this.m_rcButton.x + 1, this.m_rcButton.y + 1, this.m_rcButton.x + 1, this.m_rcButton.y + this.m_rcButton.height - 3);
- var1.setColor(var3);
- var1.drawLine(this.m_rcButton.x + 1, this.m_rcButton.y + this.m_rcButton.height - 2, this.m_rcButton.x + this.m_rcButton.width - 2, this.m_rcButton.y + this.m_rcButton.height - 2);
- var1.drawLine(this.m_rcButton.x + this.m_rcButton.width - 2, this.m_rcButton.y + 2, this.m_rcButton.x + this.m_rcButton.width - 2, this.m_rcButton.y + this.m_rcButton.height - 2);
- CRect var5 = new CRect();
- Polygon var6 = new Polygon();
- ((Rectangle)var5).reshape(this.m_rcButton.x + 4 + var4, this.m_rcButton.y + (this.m_rcButton.height - 4) / 2 + var4, 7, 4);
- var6.addPoint(var5.x, var5.y);
- var6.addPoint(var5.x + var5.width, var5.y);
- var6.addPoint(var5.x + var5.width / 2, var5.y + var5.height);
- var1.setColor(Color.black);
- var1.fillPolygon(var6.xpoints, var6.ypoints, var6.npoints);
- }
-
- public boolean ProcessMouseDown(Point var1) {
- if (this.m_bListVisible) {
- if (this.m_rcListBox.inside(var1.x, var1.y)) {
- this.m_ListBox.ProcessMouseDown(var1);
- this.m_strSelection = this.m_ListBox.GetSel();
- this.DrawControl();
- }
-
- this.m_bListVisible = false;
- this.m_bHasFocus = true;
- Globals.thePresView.Render(this.m_rcListBox);
- Globals.thePresView.Draw((Graphics)null, this.m_rcListBox);
- } else if (this.m_rcButton.inside(var1.x, var1.y)) {
- this.m_nButtonState = Utils.StateSet(this.m_nButtonState, 8);
- this.m_bListVisible = true;
- this.m_bHasFocus = true;
- this.DrawButton(Globals.thePresView.GetDC());
- this.m_ListBox.DrawControl();
- } else if (this.m_rcText.inside(var1.x, var1.y)) {
- this.m_bListVisible = true;
- this.m_bHasFocus = true;
- this.m_ListBox.DrawControl();
- }
-
- return false;
- }
-
- public void SetSelections(String var1, String var2) {
- this.m_strSelection = this.m_ListBox.SetSelections(var1, var2);
- }
-
- public void SetFont(Font var1) {
- this.m_Font = var1;
- this.m_ListBox.SetFont(var1);
- this.SetRegions();
- }
-
- public boolean SelectionValid() {
- return this.m_strSelection.length() == 0 || this.m_ListBox.FindItem(this.m_strSelection);
- }
-
- public String GetSel() {
- return this.m_strSelection;
- }
-
- public void FillListBox(String var1, String var2) {
- this.m_rcListBox.height = this.m_ListBox.FillListBox(var1, var2) + 1;
- }
-
- public boolean ListVisible() {
- return this.m_bListVisible;
- }
- }
-